using System.Collections;
using I2.Loc;
using UnityEngine;

public class BuyMessagePanel : MonoBehaviour
{
	public UILabel message;

	public float showDurationSec;

	public float fadeDurationSec;

	private IEnumerator hideCoroutine;

	public void ShowSuccesedBuy(Product product)
	{
		base.gameObject.SetActive(true);
		string text = ((product.prevProduct != null) ? ScriptLocalization.Get("Market/term_success_upgrade_product") : ScriptLocalization.Get("Market/term_success_buy_product"));
		message.text = ((!string.IsNullOrEmpty(text)) ? text : "Вы купили");
		string text2 = ScriptLocalization.Get("Market/" + product.id + "_title");
		text2 = ((!string.IsNullOrEmpty(text2)) ? text2 : "Нет локализации!");
		UILabel uILabel = message;
		uILabel.text = uILabel.text + "\n" + text2;
		string fullLocMessage;
		if (LocForVehicleUpgrade(product, out fullLocMessage))
		{
			message.text = fullLocMessage;
		}
		if (hideCoroutine != null)
		{
			StopCoroutine(hideCoroutine);
		}
		hideCoroutine = Hide(showDurationSec);
		StartCoroutine(hideCoroutine);
	}

	private bool LocForVehicleUpgrade(Product product, out string fullLocMessage)
	{
		if (product is ProductVehicleSkin)
		{
			fullLocMessage = ScriptLocalization.Get("Game_Common/CarM_skinPurchased");
			return true;
		}
		if (product is ProductVehicleUpgrade)
		{
			ProductVehicleUpgrade productVehicleUpgrade = product as ProductVehicleUpgrade;
			if (string.IsNullOrEmpty(productVehicleUpgrade.nextProductId))
			{
				fullLocMessage = ScriptLocalization.Get("Game_Common/CarM_max_moduleUpgrade");
			}
			else
			{
				fullLocMessage = ScriptLocalization.Get("Game_Common/CarM_moduleUpgrade");
			}
			return true;
		}
		fullLocMessage = string.Empty;
		return false;
	}

	private IEnumerator Hide(float time)
	{
		yield return BCWUtils.WaitForRealSeconds(time);
		hideCoroutine = null;
		base.gameObject.SetActive(false);
	}
}
